{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5976d684-d179-42c4-b2b5-33ccd2c36ad3",
   "metadata": {},
   "source": [
    "## **Numpy的计算-求每个点之间的距离**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "54c6248e-0acf-4bb3-8175-2e5f4fa1cfca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0 17 72]\n",
      " [17  0 53]\n",
      " [72 53  0]]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAQlUlEQVR4nO3db4wcd33H8feX+BDY61OqJqxS3DaqqSJQ5ISsFaBRI44AwiVCLfIDUG2pqOpVMqKJ66otfYJQVfVJ0hTJ/RcZKhpDTu2RtGrUIBCsS3kA1BuCSUiq6iAUQyFEQLiNUbnQbx/MurJ959u9/XP728n7JY32duY3O9+vonx2/LuZm8hMJEnletG0C5Akbc6glqTCGdSSVDiDWpIKZ1BLUuF2TOJDr7rqqrz22muH2ve5555j165d4y1oSurSS136AHspUV36gNF66XQ6z2Tm1RtuzMyxL61WK4fVbreH3rc0demlLn1k2kuJ6tJH5mi9AKfzMpnq1IckFc6glqTCGdSSVDiDWpJGsbICR47A/Dx0OtXrkSPV+jExqCVpWA8/DPv2wYkTsLparVtdrd7v21dtH4OBgjoi7oiIxyLi8Yi4cyxHlqRZtrICBw/CuXOwtnbxtrW1av3Bg2M5s+4b1BFxPfBbwM3ADcDtEfGLIx9ZkmbZ3XevD+hLra3BPfeMfKhBzqhfCXwuM89l5vPAvwK/NvKRJWmWnTw5WFDfd9/Ih4rs8/eoI+KVwD8BrwN+BHyK6sLs91wybhFYBGg2m62lpaWhCup2uzQajaH2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kzf5NIRHwY+LfMPBERLwZ2ZuYPplzWSCLiCuCbwGsyc9gb/y5SzBl1Zn4G+N606xhV1uhhwL0nBHV7b+d6Sxnf7FsUEXuAtwInpl2LKhExD9xK9WASMvPHsx7SPbcBK+MKaSgoqOuo9zDgVwOfn3IpQ+tNFzwKPA18MjNntZc/B34f+N8p1zEOCXwiIjq9h0rPql8Avgv8bW9K6kRE7Jp2UWPwDuD+cX6gQT0hEdGges7knXnJE9tnSWb+JDNvBPYAN0fEzE1LRcTtwNOZuf5R3rPplsy8CTgAvLs3bTiLdgA3AX+Vma8GngP+cLoljaY3ffM24B/G+bkG9QTU8WHAvX+SngLeMt1KhnIL8Lbe3O4S1WPlTk63pOFl5rd6r08DDwI3T7eioZ0Fzl7wr7RlquCeZQeARzLzO+P8UIN6zOr0MOCIuDoiruz9/FLgjcCTUy1qCJn53szck5nXUv2z9NOZeWjKZQ0lInb1fklNb5rgzcBMXimVmd8GvhER1/VW3QbM3C/dL/FOxjztAQU9iisi7gdeD1wVEWeB92XmB6db1VDOPwz4y725XYA/ysx/mV5JQ7sG+HDvt9gvAv4+M2f60rYaaAIPVucD7AA+mpkfn25JI3kP8JHelMFXgXdNuZ6hRcRO4E3Ab4/9s0u5PE+StDGnPiSpcAa1JBXOoJakwhnUklQ4g1qSCmdQS1LhDGpJKtz/AVmVE7y2DTEQAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "x = np.array([\n",
    "    [1,3],\n",
    "    [5,2],\n",
    "    [7,9]\n",
    "])\n",
    "h,w=x.shape\n",
    "\n",
    "############## 只需要填写以下3句话即可 ##############\n",
    "x1= x.reshape(-1).reshape(h,1,w)##### 想办法改变x的结构\n",
    "x2= x.reshape(-1).reshape(1,h,w)##### 想办法改变x的结构\n",
    "s = np.sum((x1-x2)**2,axis=2)##### 综合运算\n",
    "\n",
    "########## 以上三句话其实可以简写为1句话 #############\n",
    "\n",
    "\n",
    "print(s)\n",
    "# print(x1)\n",
    "# print(x2)\n",
    "fg,ax=plt.subplots()\n",
    "ax.grid()\n",
    "ax.scatter(x[:,0],x[:,1],color='red',s=100)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76984e6f-c49b-430f-8afa-1e6171a3665a",
   "metadata": {},
   "source": [
    "#### 参考答案"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "182aaf00-a6fe-49b3-a29b-91a3cc96f1bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+----------+------------+------------+------------+\n",
      "|          |   p1:(1,3) |   p2:(5,2) |   p3:(7,9) |\n",
      "+==========+============+============+============+\n",
      "| p1:(1,3) |          0 |         17 |         72 |\n",
      "+----------+------------+------------+------------+\n",
      "| p2:(5,2) |         17 |          0 |         53 |\n",
      "+----------+------------+------------+------------+\n",
      "| p3:(7,9) |         72 |         53 |          0 |\n",
      "+----------+------------+------------+------------+\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZUAAAEDCAYAAAD9ZJllAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAebUlEQVR4nO3dfXRU9b3v8fe3IchDAJWHEIrAKR4VpYgOPhRqbNCemmqpFq7aVfDWo6YV26aIvSL2Wryu04d14WAteq4WOAr0NFcD3Fvbi1pwgIMuKgQh1QIq6rGAgKFHIAErwvf+MRNKyJDZmdmTeeDzWmuvSfb+7b2/X13m4+xHc3dERETC8KlsFyAiIoVDoSIiIqFRqIiISGgUKiIiEhqFioiIhEahIiIioVGoiIhIaBQqIiI5wMwWmNkeM+ue7VoAzGyqm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t26YGT/84Q9T2se9997LVVddxVlnnUXXrl0588wzueiii3jwwQfZu3dvq/Ff/epX6devH/fcc0/KfYmI5JOCCZXp06fTs2dP7rzzzhbzp06dyhNPPMGbb77JgAED0trH7NmzaWpq4otf/CLV1dV84xvfoFOnTsyYMYMRI0bw5z//ucX40047jerqan73u9/x8ssvp7VvEZF8UBCh8sYbb7B8+XJuvPFGunbt2mJZTU0N7777Ln/5y19S/obSbP/+/axdu5b58+fz05/+lF/84hesW7eO6dOns3PnTn7yk5+0WmfixIkUFRXx2GOPpbVvEZF8UBChMn/+fNydm266qdWya665hsGDB4eyny5duiScf+ONNwLw5ptvtlo2YMAArrjiCmpra9m/f38odYiI5KqCCJXly5dTVFTE5ZdfnpX9P/vsswCMGDEi4fIxY8bw17/+ldWrV3dkWSIiHa5dd9TnoqamJjZu3MiwYcNanKDPpJkzZ9LY2Mi+fftYv349a9asYcSIEUybNi3h+EsuuQSA1atXc911rd4aICJSMPI+VHbs2MGRI0coKyvrsH3OnDmT3bt3H/v9mmuu4cknn6Rv374Jx/fv3x+A9957r0PqExHJlrw//NV8Ke8ZZ5zRYfvctWsX7s6uXbtYsmQJb7/9NhdddBEbNmxIOP7MM88EoKGhocNqFBHJhrwPlearvT766KMO33dpaSk33HADL7zwAnv37uWWW25JOO7QoUMAra5MExEpNHkfKv369QNIePNhRxk8eDDnn38+r7/+esJvI821NdcqIlKo8j5UysrK6Nu3L1u3bs1qHTt37gSgqKio1bLmx7SMHDmyI0sSEelweR8qZkZ5eTkNDQ289dZboW3TzFrM27JlC7t27Wo19ujRo9x///3s2bOH0aNHJzy3s3btWgAqKipCqU9EJFfl/dVfAOPHj2fx4sU8//zznH322S2WzZ07lzVr1gAcC51nn32W7du3A3Deeee1uBTY3YHW3ziee+45fvCDH1BeXs7QoUPp3bs3u3fvZtWqVbz99tv079+fX/7yl61qO3r0KCtWrODcc89l+PDh4TUtIpKDCiZUSktLWbBgAXfddVeLZWvWrOGpp55qMa++vp76+noArrzyyhah0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jd52W3qpSMASYBf4yfiwCY7u7/L3slpawMeCp+NcungKfdPa8vxy0ApcDS2P+70An4N3d/LrslpeW7wK/ih43eBm7Ncj0pM7NuwBeBb2W7lmzKmUuKRUQk/+nwl4iIhEahIiIioVGoiIhIaBQqIiISGoWKiIiERqEiIiKhUaiIiEhoFCoiIhKa/w8Xfui0nNRBrQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from tabulate import tabulate\n",
    "\n",
    "X = np.array([\n",
    "    [1, 3],\n",
    "    [5, 2],\n",
    "    [7, 9]\n",
    "])\n",
    "h, w = X.shape\n",
    "\n",
    "########################### 核心代码三句话 ##############################\n",
    "X1 = X.reshape(h, 1, w) # 制作一个点列\n",
    "X2 = X.reshape(1, h, w) # 制作一个点行\n",
    "s = np.sum((X1-X2)**2, axis=2) # 因为广播的机制，可以直接求两点之间的距离的平方\n",
    "########################################################################\n",
    "\n",
    "# 用tabulate更加清晰的打印效果\n",
    "names=['p1:(1,3)','p2:(5,2)','p3:(7,9)']\n",
    "print(tabulate(s,tablefmt='grid',headers=names,showindex=names),)\n",
    "\n",
    "fg, ax = plt.subplots()\n",
    "ax.grid()\n",
    "ax.scatter(X[:, 0], X[:, 1], color='red', s=100)\n",
    "for x,y in X:\n",
    "    loc=\"({0},{1})\".format(x,y)\n",
    "    ax.text(x+0.2,y+0.2,loc,size=20)\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c9a182bb-924f-4869-8994-389e704fb240",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
